package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import com.asiainfo.ysrman.doprocess.*;
import com.asiainfo.ysrman.Beans.*;
import java.util.*;
import java.text.*;

public final class UserChangeSearch_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  static {
    _jspx_dependants = new java.util.Vector(1);
    _jspx_dependants.add("/uservalidate.jsp");
  }

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=GBK");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write('\r');
      out.write('\n');
	
	//??????
	if (session.getAttribute("userid") == null||session.getAttribute("userid").equals(""))
	{	
		//response.sendRedirect("index.jsp");
		out.println("<script language=\"javaScript\">parent.document.frames.top.window.location.href='index.jsp';</script>");
		return;
	}

      out.write("\r\n");
      out.write("\r\n");

    String whereStr = "";
    String aTypeStr =  request.getParameter("aType");     
    
    String mobile = request.getParameter("mobile");
    if (mobile == null) mobile = "";
    mobile = mobile.trim();
    
    int aType = 0;
   
    if ( aTypeStr != null) aType = Integer.parseInt(aTypeStr);
  
    if (aType != 0) whereStr += " and utype="+ aType;
    else whereStr += " and utype in (-2,-3)";
   

	String txtBDate = "";
	String txtEDate = "";
	String showBDate = "";
	String showEDate = "";
	int flag = 0;
	
	
	txtBDate = request.getParameter("txtDateBegin");
	txtEDate = request.getParameter("txtDateEnd");	
	
	SimpleDateFormat sFormat = new SimpleDateFormat("yyyy-MM-dd");
	if ( (txtBDate == null ||txtBDate.equals("")) && ( txtEDate == null ||txtEDate.equals("")) )
	{		
	   	txtBDate = "2007-06-01"; 
		txtEDate = sFormat.format(new Date( new Date().getTime()+1000*60*60*24));	
	   	flag = 1;//没有开始/结束日期
	}
	else if ( txtBDate != null && ( txtEDate == null || txtEDate.equals("") ))
	{
		showBDate = txtBDate;
		txtEDate = sFormat.format(new Date( new Date().getTime()+1000*60*60*24));
		flag = 2;//只有开始日期
	}
	else if ( (txtBDate == null || txtBDate.equals(""))&& txtEDate != null)
	{
		txtBDate = "2007-06-01";  
		//txtEDate = sFormat.format(new Date( new Date().getTime()));	 
		showEDate = txtEDate;
		flag = 3;//只有结束日期
	}
	else
	{
		showBDate = txtBDate;
		showEDate = txtEDate;
		flag = 0;//有开始结束日期
	}
	String mStr = "";
	String dStr = "";
	
	mStr = txtBDate.substring(txtBDate.indexOf("-")+1,txtBDate.lastIndexOf("-"));
		 if (mStr.length()==1)
		 		mStr = "0" + mStr;
		 		
	dStr = txtBDate.substring(txtBDate.lastIndexOf("-")+1);
		if (dStr.length()==1)
		dStr = "0" + dStr;
			
	txtBDate = txtBDate.substring(0,txtBDate.indexOf("-")) + mStr + dStr + "000000";
	
	mStr = txtEDate.substring(txtEDate.indexOf("-")+1,txtEDate.lastIndexOf("-"));
		 if (mStr.length()==1)
		 		mStr = "0" + mStr;
		 		
	dStr = txtEDate.substring(txtEDate.lastIndexOf("-")+1);
		if (dStr.length()==1)
		dStr = "0" + dStr;
			
	txtEDate = txtEDate.substring(0,txtEDate.indexOf("-")) + mStr + dStr + "235959";	
	
	
	if (flag == 0)
		whereStr += " and to_char(regdate,'YYYYMMDDHH24MISS')<=" + txtEDate + " and to_char(regdate,'YYYYMMDDHH24MISS')>="+txtBDate;
	if (flag == 1)
		whereStr += " ";
	if (flag == 2)
		whereStr += " and to_char(regdate,'YYYYMMDDHH24MISS')>="+txtBDate;
	if (flag == 3)
		whereStr += " and to_char(regdate,'YYYYMMDDHH24MISS')<=" + txtEDate ;	
	
	//System.out.println("sql==" + whereStr);
       
    String pageIndexStr = request.getParameter("pageIndex");
 	if (pageIndexStr==null || pageIndexStr.trim().equals(""))
 	{
 		pageIndexStr = "1";
 	}
 	int pageIndex = Integer.parseInt(pageIndexStr);
 	int pageNum = 12;
 	int urlNum = 15;	//显示页码数量 
 	
 	YsrProcess yprocess = new YsrProcess();
 	
 	int listNum = 1;
 	if (!whereStr.trim().equals("") ) 
    	listNum = yprocess.getChangeAwardUserNum(mobile,whereStr);
	
	int pageCount = listNum / pageNum + ((listNum % pageNum == 0) ? 0 : 1);
	
	int lowerNum = pageIndex - 7;
	int upperNum = pageIndex + 7;


	if (upperNum > pageCount)
	{
		lowerNum = lowerNum - (upperNum - pageCount);
		upperNum = pageCount;
	}
	else if(upperNum < urlNum)
	{
		upperNum = urlNum;
	}
	
	if (lowerNum <= 0)
		lowerNum = 1;	
	
	StringBuffer sb = new StringBuffer(" ");
	sb.append("共有" + listNum + "条记录&nbsp;&nbsp;<a href='UserChangeSearch.jsp?pageIndex=1&aType=" + aType +  "&txtDateBegin=" + showBDate + "&txtDateEnd=" + showEDate + "&mobile=" + mobile + "'><u><font size = 2>首页</font></u></a> ");
	for(int num = lowerNum;num<=upperNum;num++)
	{
		if(num != pageIndex)
		{
			sb.append("<a href='UserChangeSearch.jsp?pageIndex="+num+"&aType=" + aType +  "&txtDateBegin=" + showBDate + "&txtDateEnd=" + showEDate + "&mobile=" + mobile + "'>"+ num + "</a> ");				
		}
		else
		{
			sb.append("<a href='UserChangeSearch.jsp?pageIndex="+num+"&aType=" + aType +  "&txtDateBegin=" + showBDate + "&txtDateEnd=" + showEDate + "&mobile=" + mobile + "'><font color='red'>"+ num + "</font></a> ");
		}

		if(num>=pageIndex+urlNum-1 || num>=pageCount)
			break;
	}
	sb.append("<a href='UserChangeSearch.jsp?pageIndex="+pageCount+"&aType=" + aType +  "&txtDateBegin=" + showBDate + "&txtDateEnd=" + showEDate + "&mobile=" + mobile + "'><u><font size = 2>尾页</font></u></a>");
	String pageUrlStr = "";
	if (lowerNum != upperNum)
		pageUrlStr = sb.toString();
	
	ArrayList al = null;
	if (!whereStr.trim().equals("") ) 
		al =  yprocess.getChangeAwardUser(mobile,whereStr,pageIndex,pageNum);  	
	
    if (showEDate.equals("")) showEDate = sFormat.format(new Date());

      out.write("\r\n");
      out.write("\r\n");
      out.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n");
      out.write("<head>\r\n");
      out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" />\r\n");
      out.write("<title>积分</title>\r\n");
      out.write("<link href=\"styles/styles.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n");
      out.write("<script language=\"JavaScript\" src=\"script/date1.js\"></script>\r\n");
      out.write("<style type=\"text/css\">\r\n");
      out.write("<!--\r\n");
      out.write("body {\r\n");
      out.write("\tbackground-color:#ffffff;\r\n");
      out.write("}\r\n");
      out.write("-->\r\n");
      out.write("</style>\r\n");
      out.write("\r\n");
      out.write("<script language=\"javascript\">\r\n");
      out.write("function isNumeric(strNumber)\r\n");
      out.write("{\r\n");
      out.write("\t//return (strNumber.search(/^(-|\\+)?\\d+(\\.\\d+)?$/));\r\n");
      out.write("\treturn (strNumber.search(/^(|)?\\d+(\\d+)?$/));\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("function onCheckMobile()\r\n");
      out.write("{\t  \r\n");
      out.write("   if (Form1.mobile.value != \"\")\r\n");
      out.write("   {\r\n");
      out.write("\tif(Form1.mobile.value.length!=11||isNumeric(Form1.mobile.value)==-1)\r\n");
      out.write("\t{\r\n");
      out.write("\t\talert(\"您填写的手机号格式不正确，请检查。\");\r\n");
      out.write("\t\tForm1.mobile.focus();\r\n");
      out.write("\t\treturn false;\r\n");
      out.write("\t}\t\r\n");
      out.write("\t\t\r\n");
      out.write("\t}\r\n");
      out.write("\tForm1.submit();\r\n");
      out.write("}\r\n");
      out.write("</script>\r\n");
      out.write("</head>\r\n");
      out.write("\r\n");
      out.write("<body>\r\n");
      out.write("<IFRAME frameBorder=0 id=CalFrame marginHeight=0 marginWidth=0 noResize scrolling=no src=\"common/calendar.htm\" style=\"DISPLAY: none; HEIGHT: 194px; POSITION: absolute; WIDTH: 148px; Z-INDEX: 100\"></IFRAME>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\t<table class=\"suoyin\" width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td width=\"18%\">中奖管理&gt;&gt;兑奖查询</td>\r\n");
      out.write("        <td width=\"82%\"></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("     </table>\r\n");
      out.write("    \r\n");
      out.write("\t<table class=\"xuanze\" width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td>\r\n");
      out.write("        <form id=\"Form1\" name=\"Form1\" method=\"post\" action=\"UserChangeSearch.jsp?pageIndex=1\">\r\n");
      out.write("\t\t  <label>\t\r\n");
      out.write("\t\t  手机号:<input name=\"mobile\" value=\"");
      out.print(mobile );
      out.write("\" size=15>\t\t \r\n");
      out.write("\t\t  <select name=\"aType\">\r\n");
      out.write("\t\t  <option value=\"0\" selected>选择奖项</option>\r\n");
      out.write("\t\t  <option value=\"-2\">30元联通IP卡</option>\r\n");
      out.write("\t\t  <option value=\"-3\">刘亦菲专辑CD</option>\r\n");
      out.write("\t\t  <option value=\"0\" >全部奖项</option>\r\n");
      out.write("\t\t  </select>\r\n");
      out.write("\t\t  </label>\r\n");
      out.write("         &nbsp;\r\n");
      out.write("          <strong>时间：</strong>\r\n");
      out.write("\t          <input name=\"txtDateBegin\" type=\"text\" value=\"");
      out.print(showBDate );
      out.write("\" id=\"txtDateBegin\" style=\"width:88px;\" readonly class=\"inputr\">\r\n");
      out.write("\t\t\t\t\t\t\t\r\n");
      out.write("\t           <a onclick=\"event.cancelBubble=true;\" href=\"javascript:ShowCalendar(document.Form1.dimg1,document.Form1.txtDateBegin,null,0,330)\">\r\n");
      out.write("\t           <img src=images/calendar.gif width=\"21\" height=\"21\" border=0 align=absmiddle id=dimg1 alt=\"选择开始时间\">\r\n");
      out.write("\t           </a>\r\n");
      out.write("\t             至\r\n");
      out.write("\t           <input name=\"txtDateEnd\" type=\"text\" value=\"");
      out.print(showEDate );
      out.write("\" id=\"txtDateEnd\" style=\"width:88px;\" readonly class=\"inputr\">\r\n");
      out.write("\t               \r\n");
      out.write("\t           <a onclick=\"event.cancelBubble=true;\" href=\"javascript:ShowCalendar(document.Form1.dimg2,document.Form1.txtDateEnd,null,0,330)\">\r\n");
      out.write("\t           <img src=images/calendar.gif width=\"21\" height=\"21\" border=0 align=absmiddle id=dimg2 alt=\"选择结束时间\">\r\n");
      out.write("\t           </a>\r\n");
      out.write("        <label>\r\n");
      out.write("        <input type=\"button\" name=\"Submit\" class=\"btn01\" value=\"确 定\" onclick=\"onCheckMobile()\" />\r\n");
      out.write("        </label>\r\n");
      out.write("        </form>\r\n");
      out.write("\t  </td>\r\n");
      out.write("     </tr>\r\n");
      out.write("    </table>\r\n");
      out.write("\r\n");
      out.write("    <table style=\"border:1px solid #CCCCCC;\" width=\"98%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("            <tr>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"5%\"><strong>序号</strong></td>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"10%\"><strong>手机号</strong></td>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"15%\"><strong>所兑奖项</strong></td>\r\n");
      out.write("              <td class=\"shujutittle\" width=\"50%\"><strong>地址</strong></td>             \r\n");
      out.write("              <td class=\"shujutittle\" width=\"20%\"><strong>中奖时间</strong></td>\r\n");
      out.write("            </tr>\r\n");
      out.write("        </table></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td>\r\n");
      out.write("        \r\n");
      out.write("        <table class=\"DoubleColorTable\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
      out.write("            ");

            if (al != null)
            {
            	int i;
            	String aStr = "30元联通IP卡";
            	String addr = "";
            	UserInfo userinfo = new UserInfo();
            	for (i=0;i<al.size();i++)
            	{
            		userinfo = (UserInfo)al.get(i);
            		if (userinfo.getInoutType()== -3)
            		{
            			aStr = "刘亦菲专辑CD";
            			addr = userinfo.getAreaname();
            		}
            		else
            		{
            			aStr = "30元联通IP卡";
            			addr = "";
            		}
            			
            		
            
      out.write("\r\n");
      out.write("\t\t            <tr>\r\n");
      out.write("\t\t              <td width=\"5%\">");
      out.print((pageIndex-1)*pageNum+i+1 );
      out.write("</td>\r\n");
      out.write("\t\t              <td width=\"10%\">");
      out.print(userinfo.getMobile() );
      out.write("</td>\r\n");
      out.write("\t\t              <td width=\"15%\">");
      out.print(aStr );
      out.write("</td>\r\n");
      out.write("\t\t              <td width=\"50%\">");
      out.print(addr );
      out.write("</td>\t\t              \r\n");
      out.write("\t\t              <td width=\"20%\">");
      out.print(userinfo.getRedate() );
      out.write("</td>\r\n");
      out.write("\t\t            </tr>\r\n");
      out.write("            ");

            	}
            }
            
      out.write("\r\n");
      out.write("            \r\n");
      out.write("            <tr> </tr>\r\n");
      out.write("        </table></td>\r\n");
      out.write("      </tr>\r\n");
      out.write("      <tr>\r\n");
      out.write("        <td style=\"padding-right:18px\" align=\"right\" colspan=6>");
      out.print(pageUrlStr );
      out.write("</td>\r\n");
      out.write("      </tr>\r\n");
      out.write("    </table>\r\n");
      out.write("   </td>\r\n");
      out.write("   </tr>\r\n");
      out.write("   </table>\r\n");
      out.write("\r\n");
      out.write("<SCRIPT language=javascript>\r\n");
      out.write("\r\n");
      out.write("var len = window.Form1.aType.options.length;\r\n");
      out.write("for (var j = 0; j < len; j++)\r\n");
      out.write("{\r\n");
      out.write("\tif ( window.Form1.aType.options[j].value == ");
      out.print(aType);
      out.write(" )\r\n");
      out.write("\t{\r\n");
      out.write("\t\twindow.Form1.aType.options[j].selected = true;\r\n");
      out.write("\t\tbreak;\r\n");
      out.write("\t}\r\n");
      out.write("}\r\n");
      out.write("</SCRIPT>\t\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
